<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #app{
            width: 100px;
            height: 100px;
            border: 1px solid #333;
        }
    </style>
</head>
<body>
    <div id="app" draggable="true">
        可拖拽
    </div>
    <script>
        /* 单位时间以外，只触发一次，如果单位时间内触发多次，只会执行一次 */
        /* 
        节流：无论拖拽一元素多快，时间都会每隔100ms触发一次 */
        let timer = null;
        const app = document.getElementById("app")
        app.addEventListener("drag",function(e){
            if(timer){
                return
            }
            timer=setTimeout(()=>{
                console.log(e.offsetX,e.offsetY);
                timer=null
            },500)
        })
    </script>
</body>
</html>